﻿using HuaWei;
using HuaWei.CommClass;
using HuaWei.Common;
using HuaWei.EI;
using HuaWei.Windows.Forms;
using System;
using System.Data;
using System.IO;
using System.Windows.Forms;

internal class Class29 : ExportBase, IExport
{
    public Class29(string _str3, string _str4, string _str5)
    {
        base.IniExport(_str3, _str4, _str5);
    }

    public bool CBRExpJLData()
    {
        try
        {
            base.ida.OpenDatabase();
            Class39.smethod5(base.QCID, GParams._BDID, GParams._XMID, GParams._YZID);
            if (!base.CheckExportData())
            {
                return false;
            }
            base.method7(GParams._JGLX);
            base.method9(GParams._XMID);
            string pathName = AppDomain.CurrentDomain.BaseDirectory + @"DCFile\";
            string sourceFileName = string.Concat(new object[] { Convert.ToString(1), 'z', base.BDID, 'z', base.QCID, 'z', GParams.LoginId, ".xml" });
            string destFileName = base.BDName + "-" + base.QCID + "期.zip";
            base.dsSource.WriteXml(pathName + sourceFileName, XmlWriteMode.WriteSchema);
            FileZip.zipFile(pathName, sourceFileName, destFileName, "");
            File.Delete(pathName + sourceFileName);
            MsgBox.ShowMsg("导出数据已完成！");
        }
        catch (Exception exception)
        {
            base.ida.RollBack();
            MsgBox.ShowError("导出数据时出错，请与管理员系统！", exception);
            return false;
        }
        finally
        {
            base.ida.CloseDatabase();
        }
        return true;
    }

    public bool ExpDataByJGLX()
    {
        switch (GParams._JGLX)
        {
            case JGLX.YZ:
                base.BDName = GParams._str + "-" + base.BDName;
                return this.imethod_2();

            case JGLX.JL:
                base.BDName = GParams._str + "-" + base.BDName;
                return this.imethod_1();

            case JGLX.CBR:
                base.BDName = base.BDName;
                return this.CBRExpJLData();
        }
        return true;
    }

    public bool imethod_0()
    {
        FrmDataXD axd = new FrmDataXD();
        if (axd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            string xMID = axd.XMID;
            string xMName = axd.XMName;
            try
            {
                base.ida.OpenDatabase();
                base.method9(xMID);
                string pathName = AppDomain.CurrentDomain.BaseDirectory + @"DCFile\";
                string destFileName = "";
                string sourceFileName = string.Concat(new object[] { Convert.ToString(3), 'z', xMID, 'z', 'z', GParams.LoginId, ".xml" });
                destFileName = xMName + ".zip";
                base.dsSource.WriteXml(pathName + sourceFileName, XmlWriteMode.WriteSchema);
                FileZip.zipFile(pathName, sourceFileName, destFileName, "");
                File.Delete(pathName + sourceFileName);
                MsgBox.ShowMsg(string.Format("导出{0}信息已完成！", xMName));
            }
            catch (Exception exception)
            {
                base.ida.RollBack();
                MsgBox.ShowError("系统出错，请与管理员系统！", exception);
                return false;
            }
            finally
            {
                base.ida.CloseDatabase();
            }
        }
        return true;
    }

    public bool imethod_1()
    {
        try
        {
            Class39.smethod5(base.QCID, GParams._BDID, GParams._XMID, GParams._YZID);
            DataSet set = new DataSet();
            base.ida.OpenDatabase();
            if (!base.CheckExportData())
            {
                return false;
            }
            base.BuildJLSPData();
            base.method6(false);
            base.method9(GParams._XMID);
            string sourceFileName = "";
            string destFileName = "";
            string pathName = AppDomain.CurrentDomain.BaseDirectory + @"DCFile\";
            sourceFileName = string.Concat(new object[] { Convert.ToString(1), 'z', base.BDID, 'z', base.QCID, 'z', GParams.LoginId, ".xml" });
            destFileName = base.BDName + "-" + base.QCID + "期.zip";
            set.WriteXml(pathName + sourceFileName, XmlWriteMode.WriteSchema);
            FileZip.zipFile(pathName, sourceFileName, destFileName, "");
            File.Delete(pathName + sourceFileName);
            this.JLExpDelJLData(pathName + base.BDName + "-" + base.QCID + "期-审批删除的数据.txt");
            MsgBox.ShowMsg("导出数据已完成！");
        }
        catch (Exception exception)
        {
            base.ida.RollBack();
            MsgBox.ShowError("导出数据时出错，请与管理员系统！", exception);
            return false;
        }
        finally
        {
            base.ida.CloseDatabase();
        }
        return true;
    }

    public bool imethod_2()
    {
        try
        {
            base.ida.OpenDatabase();
            Class39.smethod15(base.BDID, base.QCID, GParams._XMID, GParams._YZID, true, true);
            if (!base.CheckExportData())
            {
                return false;
            }
            base.BuildJLSPData();
            base.method4(1);
            base.method6(false);
            base.method9(GParams._XMID);
            string exeStr = "";
            exeStr = string.Format("select * from {0} where bdid='#bdid#' and qcid={1}", "REP_ZQZFZS", base.QCID);
            base.ExecuteDataSetEx(base.dsSource, exeStr, "REP_ZQZFZS");
            exeStr = string.Format("select * from {0} where bdid='#bdid#' and qcid={1}", "REP_GCBG", base.QCID);
            base.ExecuteDataSetEx(base.dsSource, exeStr, "REP_GCBG");
            Log.Write("报表数据");
            string sourceFileName = "";
            string destFileName = "";
            string pathName = AppDomain.CurrentDomain.BaseDirectory + @"DCFile\";
            sourceFileName = string.Concat(new object[] { Convert.ToString(0), 'z', base.BDID, 'z', base.QCID, 'z', GParams.LoginId, ".xml" });
            destFileName = base.BDName + "-" + base.QCID + "期.zip";
            base.dsSource.WriteXml(pathName + sourceFileName, XmlWriteMode.WriteSchema);
            FileZip.zipFile(pathName, sourceFileName, destFileName, "");
            File.Delete(pathName + sourceFileName);
            MsgBox.ShowMsg("导出数据已完成!!");
            Log.Write("导出数据已完成");
        }
        catch (Exception exception)
        {
            base.ida.RollBack();
            MsgBox.ShowError("导出数据时出错，请与管理员系统！", exception);
            return false;
        }
        finally
        {
            base.ida.CloseDatabase();
        }
        return true;
    }

    public bool imethod_3()
    {
        try
        {
            base.ida.OpenDatabase();
            base.method6(true);
            string sourceFileName = "";
            string destFileName = "";
            string pathName = AppDomain.CurrentDomain.BaseDirectory + @"DCFile\";
            sourceFileName = string.Concat(new object[] { Convert.ToString(5), 'z', base.BDID, 'z', 'z', GParams.LoginId, ".xml" });
            destFileName = base.BDName + "-解锁令.zip";
            base.dsSource.WriteXml(pathName + sourceFileName, XmlWriteMode.WriteSchema);
            FileZip.zipFile(pathName, sourceFileName, destFileName, "");
            File.Delete(pathName + sourceFileName);
            MsgBox.ShowMsg("下达解锁令已完成！");
        }
        catch (Exception exception)
        {
            MsgBox.ShowError("下达解锁令出错！", exception);
            return false;
        }
        finally
        {
            base.ida.CloseDatabase();
        }
        return true;
    }

    public bool JLExpDelJLData(string filePath)
    {
        try
        {
            string keyValue = "";
            string str2 = "";
            string str3 = "";
            DataSet ds = new DataSet();
            string exeStr = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "QDJL_M3", base.BDID, base.QCID);
            base.ExecuteDataSetEx(ds, exeStr, "QDJL_M3");
            DataTable table = ds.Tables["QDJL_M3"];
            foreach (DataRow row in table.Rows)
            {
                str3 = string.Concat(new object[] { "凭证编号:", row["PZBH"], "  起讫桩号:", row["QQZH"], "  图纸编号:", row["TZBH"], "  部位:", row["BW"], "  中间交工证书编号:", row["ZJJGZSBH"] });
                if (row["spzt"].Equals(2))
                {
                    if (!str2.Equals(""))
                    {
                        str2 = str2 + "\n";
                    }
                    str2 = str2 + str3;
                }
                else
                {
                    if (!keyValue.Equals(""))
                    {
                        keyValue = keyValue + "\n";
                    }
                    keyValue = keyValue + str3;
                }
            }
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            if (keyValue != "")
            {
                IniFile.WriteIniFile(filePath, "删除", "", keyValue, false);
            }
            if (str2 != "")
            {
                IniFile.WriteIniFile(filePath, "转下期", "", str2, false);
            }
        }
        catch
        {
            return false;
        }
        return true;
    }

    public bool YZExpBGLData()
    {
        bool flag;
        try
        {
            base.ida.OpenDatabase();
            base.BuildBGLData();
            string sourceFileName = "";
            string destFileName = "";
            string pathName = AppDomain.CurrentDomain.BaseDirectory + @"DCFile\";
            sourceFileName = string.Concat(new object[] { Convert.ToString(4), 'z', base.BDID, 'z', 'z', GParams.LoginId, ".xml" });
            destFileName = base.BDName + "-变更令.zip";
            base.dsSource.WriteXml(pathName + sourceFileName, XmlWriteMode.WriteSchema);
            FileZip.zipFile(pathName, sourceFileName, destFileName, "");
            File.Delete(pathName + sourceFileName);
            MsgBox.ShowMsg("导出变更令已完成！");
            flag = true;
        }
        catch (Exception exception)
        {
            MsgBox.ShowError("导出变更令时出错", exception);
            throw exception;
        }
        finally
        {
            base.ida.CloseDatabase();
        }
        return flag;
    }
}

